package jnpf.engine.custom.cmd.tasks;

import jnpf.engine.util.SpringContextHolder;
import org.flowable.common.engine.impl.db.SuspensionState;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntityManager;

/**
 * @desc 取消委派的cmd
 */
public class ActiveTaskCmd implements Command<Void> {
    protected  String taskId;
    @Override
    public Void execute(CommandContext commandContext) {
        SpringProcessEngineConfiguration springProcessEngineConfiguration = SpringContextHolder.getBean(SpringProcessEngineConfiguration.class);
        TaskEntityManager taskEntityManager = springProcessEngineConfiguration.getTaskServiceConfiguration().getTaskEntityManager();
        TaskEntity taskEntity = taskEntityManager.findById(taskId);
        taskEntity.setSuspensionState(SuspensionState.ACTIVE.getStateCode());
        taskEntityManager.update(taskEntity);
        return null;
    }

    public ActiveTaskCmd(String taskId) {
        this.taskId = taskId;
    }
}
